<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
<link rel="stylesheet" href="/layui/css/layui.css">
<script src="/layui/layui.js"></script>
<style type="text/css">
	.layui-table-tips-main{display:none}
	.layui-table-tips-c{display:none}
</style>
</head>
<body class="layui-layout-body">
	<div class="layui-form"  style="margin-top: 20px;">
		<div class="layui-form toolbar">
			<div class="layui-form-item">
				<div class="layui-inline">
					<div class="layui-inline">
						<div class="layui-input-inline mr0" style="margin-left: 10px;">
							<input id="authEdtSearch" class="layui-input" type="text" autocomplete="off" placeholder="输入查询关键字">
						</div>
					</div>
					<div class="layui-inline">
						<button id="authBtnSearch" class="layui-btn icon-btn layui-btn-normal"><i class="layui-icon"></i>搜索</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!--  数据data -->
	<div class="layui-row" style="padding: 0px 10px;" id="tablediv">
		<table id="table_data" lay-filter="test"  ></table>	
	</div>
	<!-- 表格操作列 -->
	<script type="text/html" id="authTableBar">
  		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">题目详情</a>
  		<a class="layui-btn layui-btn-orange layui-btn-xs"  lay-event="queryedit">审核通过</a>
	</script>
	<script type="text/javascript">
		$(top.hangge());	
	</script>
	<script type="text/javascript">
	var tableIns ;
	var layer ;
	layui.use(['layer', 'form', 'table','element'], function(){
		  var table = layui.table;
		  var form = layui.form;
		  var element = layui.element;
		  layer=layui.layer;
		  
		  //加载层
		  var loadingIndex =layer.msg('数据加载中...', {
			   icon: 16
			  ,shade: 0.01
		  });  
		  
		  //第一个实例
		  var params = {};
		  tableIns = table.render({
		    elem: '#table_data',
		    url: '/admin/topic/findListData2?option=2',
		    page: true, //开启分页
		    where:params,
		    loading:true,
		    height: 'full-150',
		    cols: [
		    	[ //表头
		    	{field:'tid',title: '编号', hide: true}
               , {field: 'tsn', title: '知识编号',width:110}
               , {field: 'tgrade', title: '知识年级',width:110,templet:function(t){
            	   if(t.tgrade==0){
            		   return '初三上册';
            	   } else if(t.tgrade==0){
            		   return '初三下册';
            	   } else if(t.tgrade==1){
            		   return '高一上册';
            	   } else if(t.tgrade==2){
            		   return '高一下册';
            	   } else if(t.tgrade==3){
            		   return '高二上册';
            	   } else if(t.tgrade==4){
            		   return '高二下册';
            	   } else if(t.tgrade==5){
            		   return '高三上册';
            	   } else if(t.tgrade==6){
            		   return '高三下册';
            	   }
               }}
               , {field: 'tclassify', title: '知识分类',width:160,templet:function(t){
            	   if(t.tclassify==0){
            		   return '元素表';
            	   } else if(t.tclassify==1){
            		   return '燃烧';
            	   } else if(t.tclassify==2){
            		   return '空气成分';
            	   } else if(t.tclassify==3){
            		   return '溶解沉淀平衡';
            	   } else if(t.tclassify==4){
            		   return '电离平衡';
            	   } else if(t.tclassify==5){
            		   return '有机物';
            	   } else if(t.tclassify==6){
            		   return '其他';
            	   } 
               }}
               , {field: 'tdifficulty', title: '难度系数',templet:function(t){
            	   if(t.tdifficulty==0){
            		   return '★';
            	   } else if(t.tdifficulty==1){
            		   return '★★';
            	   } else if(t.tdifficulty==2){
            		   return '★★★';
            	   } else if(t.tdifficulty==3){
            		   return '★★★★';
            	   } else if(t.tdifficulty==4){
            		   return '★★★★★';
            	   } 
               }}
               , {field: 'ttype', title: '试题类型',templet:function(t){
            	   if(t.ttype==0){
            		   return '单项选择题';
            	   } else if(t.ttype==1){
            		   return '多项选择题';
            	   } else if(t.ttype==2){
            		   return '判断题';
            	   } else if(t.ttype==3){
            		   return '填空题';
            	   } else if(t.ttype==4){
            		   return '计算题';
            	   } else if(t.ttype==5){
            		   return '其他类型';
            	   }
               }}
               , {field: 'tauname', title: '上传作者'}
               , {field: 'ttime', title: '添加时间',width:180}
               , {field: 'tispopup', title: '是否上线',width:110, templet:function(c){
            	   if(c.tispopup==0){
            		   return "未上线";
            	   } else {
            		   return "已上线"
            	   }
               }}
		       , {templet: '#authTableBar', width: 180, align: 'center', title: '操作'}
		    	]
		   		],
		    done:function(res){
		    	layer.close(loadingIndex);
		    }
		  });
		  
		  table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
			  var data = obj.data //获得当前行数据
			    ,layEvent = obj.event; //获得 lay-event 对应的值
			    var tid=data.tid;
			    if(layEvent === 'edit'){
			    	showEditModel(tid);
			    } else if(layEvent === 'queryedit'){
			    	showQueryEditModel(tid);
			    } 
		});
	});
	
	
	function showEditModel(tid){
		layer.open({
			  title:'查看知识信息',
			  content: '/admin/topic/edit2?id='+tid,
			  type: 2, 
			  area: ['100%', '100%'],
			  cancel: function(index, layero){ 
				  
			  },
			  end:function(){
				  Refresh();
			  }
		});
	}
	
	//搜索
	$("#authBtnSearch").click(function(){
		Refresh();
	});
	//刷新
	function Refresh(){
		var params = {};
		var authEdtSearch=$("#authEdtSearch").val();
		var kispopup=$("#kispopup").val();
		params.keywords=authEdtSearch;
		params.kispopup=kispopup;
		tableIns.reload({
			  where:params
			  ,page: {
				    curr: 1 //重新从第 1 页开始
				  }
		});	
	}
	
	//处理
	function showQueryEditModel(tid){
		layer.confirm('试题是否直接上线?', { btn: ['直接上线','放入仓库'],btn1: function(index){
    		var params={};
    		params.id = tid;
    		params.tispopup=1;
    		$.ajax( {
   	         url : '/admin/topic/modification2', 
   	         type : 'post',
   	         data: params,
   	         dataType : 'json',
   	         success : function(data) {
   	        	 if(data.code==0){
   	        		 layer.msg(data.msg,{icon: 1});
   	        		 Refresh();
   	        	 }else{
   	        		 layer.msg(data.msg,{icon: 2});
   	        	 }
   	         }
   	     });
            },
            btn2: function(){
            	var params={};
        		params.id = tid;
        		params.tispopup=0;
        		$.ajax( {
       	         url : '/admin/topic/modification2', 
       	         type : 'post',
       	         data: params,
       	         dataType : 'json',
       	         success : function(data) {
       	        	 if(data.code==0){
       	        		 layer.msg(data.msg,{icon: 1});
       	        		 Refresh();
       	        	 }else{
       	        		 layer.msg(data.msg,{icon: 2});
       	        	 }
       	         }
       	     });
            }
            
        })
	}
	</script>


</body>
</html>